
$(function() {
	$("#form_add").validate({
		rules: {
			name: {
				required: true,
				minlength: 2
			},
			price: {
				required: true
			},
			unit: "required"
		},
		messages: {
			name: {
				required: "请输入物料名称",
				minlength: $.validator.format("请输入字数不少于{0}个的名称")
			},
			unit: {
				required: "请输入物料的单位"
			},
			price: {
				required: "请输入物料的单价"
			}
		},
		errorPlacement: function(label, element) {
			label.insertAfter(element);
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});

	$('#category_t').selectChain({
		target: $('#subclass_t'),
		key: "code",
		value: "name",
		url: 'material.php?do=Material.ajax_category',
		data: { ajax: true }
	}).trigger('change');
	
	_change("input[id='category']:visible", "select[id^='category_t']:visible");
	
	_change("input[id='subclass']:visible", "select[id^='subclass_t']:visible");
	 
	_change("input[id='unit']:visible", "select[id^='unit_t']:visible");

	$('textarea').css("width", 400);
	
	Tip.emp('负责人');
});

function cart(url) {
	// $.blockUI({ message: $('#loading') });

	$.get(url, function(data) {
		$('#dialog_add').html(data);
	});
}